import { createAPI } from '@/apis/rule'

export default {
  /**
   * 约定：
  * data,methods ,computed里面变量和方法名统统以add开头
   */
  data() {
    return {
      addDialogFormData: {
        type: 'add',
        dialogVisible: false,
        title: '添加停车计费规则',
        form: {
          ruleNumber: '', //计费规则编号
          ruleName: '', //计费规则名称
          freeDuration: '', //免费时长（分钟）
          chargeCeiling: '',//收费上限（元）
          chargeType: '',//计费方式
          ruleNameView: ''//计费规则
        }
      }
    }
  },
  methods: {
    addResetFrom() {
      this.addDialogFormData.form = {
        ruleNumber: '',
        ruleName: '',
        freeDuration: 0,
        chargeCeiling: '',
        chargeType: '',
        ruleNameView: '',
      }
    },
    async addComfirmForm() {
      const params = this.addDialogFormData.form
      try {
        const r = await createAPI(params)
        this.addResetFrom() //把数据清空了
        this.$message.success('添加成功')
        this.fetchTableData()

      } catch (error) {
        this.$message.error(error.msg || '添加失败')

      }

    }
  },
}